| Conditions | 4 |
| Paths | 16385 |
| Total Lines | 167 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | // Copyright © 2017 Tangdongxin |
||
| 25 | function onConfig (result) { |
||
| 26 | |||
| 27 | if (!result) { // {{{ |
||
| 28 | |||
| 29 | dlog('No Config find'); |
||
| 30 | fontStyle = 'Consolas'; |
||
|
|
|||
| 31 | fontSize = '14px'; |
||
| 32 | bgColor = '#FDF6E3'; |
||
| 33 | intColor = '#657A81'; |
||
| 34 | strColor = '#2AA198'; |
||
| 35 | keyColor = '#B58900'; |
||
| 36 | defaultColor = '#586E75'; |
||
| 37 | |||
| 38 | strictOnly = false; |
||
| 39 | hideDetails = false; |
||
| 40 | dontBeatify = false; |
||
| 41 | isHighlight = false; |
||
| 42 | isDebug = false; |
||
| 43 | |||
| 44 | strLength = 300; |
||
| 45 | return; |
||
| 46 | |||
| 47 | }// }}} |
||
| 48 | |||
| 49 | if (result && result[0]) { // {{{ |
||
| 50 | |||
| 51 | fontStyle = result[0].fontStyle || 'Consolas'; |
||
| 52 | fontSize = result[0].fontSize || '14px'; |
||
| 53 | bgColor = result[0].bgColor || '#FDF6E3'; |
||
| 54 | intColor = result[0].intColor || '#657A81'; |
||
| 55 | strColor = result[0].strColor || '#2AA198'; |
||
| 56 | keyColor = result[0].keyColor || '#B58900'; |
||
| 57 | defaultColor = result[0].defaultColor || '#586E75'; |
||
| 58 | |||
| 59 | strictOnly = result[0].strictOnly || false; |
||
| 60 | hideDetails = result[0].hideDetails || false; |
||
| 61 | dontBeatify = result[0].dontBeatify || false; |
||
| 62 | isHighlight = result[0].isHighlight || false; |
||
| 63 | isDebug = result[0].isDebug || false; |
||
| 64 | strLength = result[0].strLength || 300; |
||
| 65 | |||
| 66 | } else { |
||
| 67 | |||
| 68 | fontStyle = result.fontStyle || 'Consolas'; |
||
| 69 | fontSize = result.fontSize || '14px'; |
||
| 70 | bgColor = result.bgColor || '#FDF6E3'; |
||
| 71 | intColor = result.intColor || '#657A81'; |
||
| 72 | strColor = result.strColor || '#2AA198'; |
||
| 73 | keyColor = result.keyColor || '#B58900'; |
||
| 74 | defaultColor = result.defaultColor || '#586E75'; |
||
| 75 | |||
| 76 | strictOnly = result.strictOnly || false; |
||
| 77 | hideDetails = result.hideDetails || false; |
||
| 78 | dontBeatify = result.dontBeatify || false; |
||
| 79 | isHighlight = result.isHighlight || false; |
||
| 80 | isDebug = result.isDebug || false; |
||
| 81 | strLength = result.strLength || 300; |
||
| 82 | |||
| 83 | }// }}} |
||
| 84 | |||
| 85 | document.addEventListener('click', function (e) { |
||
| 86 | |||
| 87 | dlog(document.contentType); |
||
| 88 | if (!document.contentType.includes('json')) { |
||
| 89 | |||
| 90 | return; |
||
| 91 | |||
| 92 | } |
||
| 93 | |||
| 94 | dlog(e); |
||
| 95 | |||
| 96 | const target = e.target; |
||
| 97 | if (target.tagName.toUpperCase() == 'I') { // {{{ |
||
| 98 | |||
| 99 | const isClose = target.classList.contains(COLL); |
||
| 100 | const classname = target.classList[0]; |
||
| 101 | if (isClose) { |
||
| 102 | |||
| 103 | target.removeAttribute('class'); |
||
| 104 | target.setAttribute('class', classname); |
||
| 105 | |||
| 106 | } else { |
||
| 107 | |||
| 108 | target.removeAttribute('class'); |
||
| 109 | target.setAttribute('class', `${classname } C${ classname.substring(1)}`); |
||
| 110 | |||
| 111 | } |
||
| 112 | e.preventDefault(); |
||
| 113 | // }}} |
||
| 114 | |||
| 115 | } else if (target.tagName.toUpperCase() == 'STR') { // {{{ |
||
| 116 | |||
| 117 | var parentElement = target.parentElement; |
||
| 118 | const originStr = parentElement.innerHTML; |
||
| 119 | parentElement.innerHTML = parentElement.getAttribute('content'); |
||
| 120 | parentElement.setAttribute('content', originStr); |
||
| 121 | // }}} |
||
| 122 | |||
| 123 | } else if (target.tagName.toUpperCase() == 'JSON') { // {{{ |
||
| 124 | |||
| 125 | if (document.getElementById('light')) { |
||
| 126 | |||
| 127 | var lightDiv = document.getElementById('light'); |
||
| 128 | lightDiv.parentElement.removeChild(lightDiv); |
||
| 129 | |||
| 130 | } |
||
| 131 | if (document.getElementById('fade')) { |
||
| 132 | |||
| 133 | var fadeDiv = document.getElementById('fade'); |
||
| 134 | fadeDiv.parentElement.removeChild(fadeDiv); |
||
| 135 | |||
| 136 | } |
||
| 137 | |||
| 138 | var parentElement = target.parentElement; |
||
| 139 | |||
| 140 | var fadeDiv = document.createElement('div'); |
||
| 141 | fadeDiv.setAttribute('id', 'fade'); |
||
| 142 | fadeDiv.classList.add('black_overlay'); |
||
| 143 | document.body.appendChild(fadeDiv); |
||
| 144 | |||
| 145 | var lightDiv = document.createElement('div'); |
||
| 146 | lightDiv.setAttribute('id', 'light'); |
||
| 147 | lightDiv.classList.add('white_content'); |
||
| 148 | document.body.appendChild(lightDiv); |
||
| 149 | |||
| 150 | document.getElementById('light').style.display = 'block'; |
||
| 151 | document.getElementById('fade').style.display = 'block'; |
||
| 152 | draw(eval(parentElement.getAttribute('json')), lightDiv); |
||
| 153 | // }}} |
||
| 154 | |||
| 155 | } else if (target.classList.contains('black_overlay')) { // {{{ |
||
| 156 | |||
| 157 | var fadeDiv = document.getElementById('fade'); |
||
| 158 | fadeDiv.parentElement.removeChild(fadeDiv); |
||
| 159 | var lightDiv = document.getElementById('light'); |
||
| 160 | lightDiv.parentElement.removeChild(lightDiv); |
||
| 161 | // }}} |
||
| 162 | |||
| 163 | } else if (target.className.toUpperCase() == DIV.toUpperCase()) { // {{{ |
||
| 164 | |||
| 165 | if (isHighlight) { |
||
| 166 | |||
| 167 | if (target.style.borderLeft) { |
||
| 168 | |||
| 169 | target.removeAttribute('style'); |
||
| 170 | |||
| 171 | } else { |
||
| 172 | |||
| 173 | target.style = 'border-left:1px solid'; |
||
| 174 | |||
| 175 | } |
||
| 176 | |||
| 177 | } |
||
| 178 | // }}} |
||
| 179 | |||
| 180 | } else if (target.tagName.toUpperCase() === 'URL') { // {{{ |
||
| 181 | |||
| 182 | url = target.parentElement.getAttribute('url'); |
||
| 183 | dlog(`go:${ url}`); |
||
| 184 | window.open(url); |
||
| 185 | // }}} |
||
| 186 | |||
| 187 | } |
||
| 188 | |||
| 189 | }, true); |
||
| 190 | |||
| 191 | } |
||
| 192 |